import { observable, action } from 'mobx';

import { ListViewPage, SearchAdvanced } from 'weaver-mobile-page';
import { Bubble,Tools,Modal } from 'weaver-mobile'
import * as Api from '../../api/CenterApi';
import { PARAMS } from '../../util';

const getLabel = Tools.getLabel;
const alert = Modal.alert;

export default class ContentMonitorStore {

    @observable viewRight = 0;//页面权限
    @observable contentpage = 'undelete';
    @observable contentvisible = false;
    @observable contentLoading = true;
    @observable contentSearch = new SearchAdvanced.Store({ route: '/center/content', id: 'contentSearch' }); //内容监控-高级搜索
    @observable contentList = new ListViewPage.Store({ route: '/center/content', id: 'content' });  // 内容监控列表
    @observable showContentCheck = false; //内容监控-批量操作
    @observable contentAdValue = ''; //高级搜索值受控

    @observable contentDeleteLoading = true;
    @observable contentDeleteSearch = new SearchAdvanced.Store({ route: '/center/content', id: 'contentDeleteSearch' }); //内容监控（已删除）-高级搜索
    @observable contentDeleteList = new ListViewPage.Store({ route: '/center/content', id: 'contentDelete' });  // 内容监控（已删除）列表
		@observable contentDeleteAdValue = ''; //高级搜索值受控
		@observable currentModel = {}; //当前对话框弹窗

    @action setStoreState = (params) => {
        Object.keys(params).forEach(key => {
          this[key] = params[key];
        })
      }

    /*************************************************** 内容监控 ***************************************************/
    @action('内容监控列表请求')
    getContentList = () => {
    const contentSearchParams = this.contentSearch.form.formParams || {};
    const params = {
            isDeleted: 0,
            datetype:0,
            typeid: '0',
            ...contentSearchParams,
        }
    Api.getCoworkDiscussMonitorList(params).then(res => {
        const dataKey = res.sessionkey;
        this.viewRight = res.viewRight
        if(this.viewRight === 0 ){
          this.contentLoading = false;
        }
        else if (dataKey) {
            this.dataKey = dataKey;
            this.contentList.getData({ dataKey }, ()=> this.contentLoading = false, true);
            this.contentLoading = false;

        }
    })
    }

    @action("内容监控高级搜索")
    getCoworkDiscussMonitorShareCondition = (params) => {
    params = {  
        ...params,
        ...PARAMS,
    }
    if(params.contentType === "delete"){
        this.contentDeleteSearch.getData({
            url: '/api/cowork/discussMonitor/getCoworkDiscussMonitorShareCondition',
            method: 'GET',
            params:params,
        })
    }else{
        this.contentSearch.getData({
            url: '/api/cowork/discussMonitor/getCoworkDiscussMonitorShareCondition',
            method: 'GET',
            params:params,
        })
    }
  
    }

    @action("内容监控删除")
    batchDiscussDel = (params) => {
     
        // alert(getLabel(388758, '确认要删除吗？'),'', [
        //     { text: getLabel(31129, '取消') },
        //     {
        //     text: getLabel(33703, '确认'),
        //     onPress: () => {
        //         Api.batchDiscussDel(params).then(res => {
        //             const status = res.status;
        //             if (status === "1") {
        //             this.getContentList();
        //             Bubble.success(getLabel(30700, '操作成功')+'!', 1);
        //             }
        //         })
        //     }
        //     },
        // ])
        this.currentModel = alert(getLabel(390686, '确认要删除该内容')+'？', '', [
            { text: getLabel(390687, '只删除该内容'), onPress: () => {
                params = {
                    isDeleteAll:0,
                    ...params,
                }
                Api.batchDiscussDel(params).then(res => {
                    const status = res.status;
                    if (status === "1") {
                    this.getContentList();
                    this.doContentCancel();
                    Bubble.success(getLabel(30700, '操作成功')+'!', 1);
                    } })
            }},
            { text: getLabel(390688, '同时删除该内容的所有评论'), onPress: () => {
                params = {
                    isDeleteAll:1,
                    ...params,
                }
                Api.batchDiscussDel(params).then(res => {
                    const status = res.status;
                    if (status === "1") {
                    this.getContentList();
                    this.doContentCancel();
                    Bubble.success(getLabel(30700, '操作成功')+'!', 1);
                    } })
            }},
            { text: getLabel(201, '取消'), },
           ])
    }

    // 内容监控 -- 高级搜索内外name统一
    @action updateContentAdvance = (value) => {
    this.contentAdValue = value;
    this.contentSearch.form.updateField('remark', value);
    }

    // 内容监控 -- 取消
    @action doContentCancel = () => {
    this.showContentCheck = false;
    this.doContentselectNone();
    }

    // 内容监控 -- 全选
    @action doContentSelectAll = () => this.contentList.selectAll();

    // 内容监控 -- 取消全选
    @action doContentselectNone = () => this.contentList.selectNone();

    // 内容监控 -- 高级搜素 -- 重置
    @action doContentReset = () => {
    this.contentSearch.form.resetFields();
    this.contentAdValue = '';
    this.getContentList();
    }

    // 内容监控 -- 组件挂载时处理
    @action doContentMount = () => {
    this.contentSearch.form.resetFields();
    this.contentAdValue = '';
    }

    /*************************************************** 内容监控已删除 ***************************************************/
    @action('内容监控已删除列表请求')
    getContentDeleteList = () => {
    const contentSearchParams = this.contentDeleteSearch.form.formParams || {};
    const params = {
        isDeleted: 1,
        del_datetype:0,
        typeid: '0',
        ...contentSearchParams,
    }
    Api.getCoworkDiscussMonitorList(params).then(res => {
        const dataKey = res.sessionkey;
        if (dataKey) {
            this.dataKey = dataKey;
            this.contentDeleteList.getData({ dataKey }, ()=> this.contentDeleteLoading = false, true);
            this.contentDeleteLoading = false;
           
        }
    })
    }

    // 内容监控 -- 高级搜索内外name统一
    @action updateContentDeleteAdvance = (value) => {
        this.contentDeleteAdValue = value;
        this.contentDeleteSearch.form.updateField('remarkBack', value);
    
    }
    // 内容监控 -- 高级搜素 -- 重置
    @action doContentDeleteReset = () => {
        this.contentDeleteSearch.form.resetFields();
        this.contentDeleteAdValue = '';
        this.getContentDeleteList();
    }
    
        // 内容监控 -- 组件挂载时处理
    @action doContentDeleteMount = () => {
        this.contentDeleteSearch.form.resetFields();
        this.contentDeleteAdValue = '';
        this.contentpage = 'undelete';
		}
		
	//关闭所有弹窗
	@action closeAllModel = () => {
		this.currentModel && typeof this.currentModel.close === 'function' && this.currentModel.close();
	}

}